home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
MACD 5
/
MACD 5.bin
/
workbench
/
libs
/
newlooklib.lha
/
newlook
/
test.c
< prev
next >
Wrap
C/C++ Source or Header
|
1993-11-07
|
6KB
|
246 lines
/*
* NewLook's TEST.C
*/
#include <exec/types.h>
#include <exec/memory.h>
#include <intuition/intuition.h>
#include <graphics/gfx.h>
#include <graphics/gfxbase.h>
#include <graphics/rastport.h>
#include "newlook.h"
extern VOID DrawBorder( struct RastPort *, struct Border *, WORD, WORD );
#ifndef AUTOSCROLL
#define AUTOSCROLL 0x4000 /* V36+ */
#endif
/* The NewWindow Flags and IDCMPFlags */
#define NW_FLAGS (WINDOWCLOSE|WINDOWDEPTH|WINDOWSIZING|WINDOWDRAG|ACTIVATE| \
SMART_REFRESH|RMBTRAP)
#define NW_IDCMP (CLOSEWINDOW|GADGETUP|VANILLAKEY)
struct Window *w= (struct Window *)NULL;
struct Gadget *b0, *b1, *b2;
const ULONG MyNewLookHandle= 42L;
STRPTR CycleTexts[]= { "Cycle",
"Saikel",
"Zeigel",
NULL
};
STRPTR ListViewTexts[]= { "This",
"is a selfmade",
"ListView",
"Gadget",
NULL
};
char *whichwitch= "r";
struct ScalebarInfo *si;
long sN= 0;
void closeit()
{
if(w)
{ CloseWindow(w);
w= (struct Window *)NULL;
}
SmartFreeAll(MyNewLookHandle);
/* just to be sure... */
/*SmartFreeAll(MAGIC_HANDLE);*/
}
int openit()
{
struct NewWindow *nw;
struct Gadget *glist;
(void)SetNewLookHandle(MyNewLookHandle);
/* create gadgets */
{ struct Gadget *g;
if( g= CreateButton(20,20,80,15,"_Button",0x0B) )
{ glist= g;
g->Activation |= TOGGLESELECT;
b0= g;
g->NextGadget= CreateButton(120,20,80,15,"nottuB",0x0D);
if(g= g->NextGadget)
{ b1= g;
g->Flags= GADGHBOX;
(void)AddGText(g,NULL,"depends on Button state");
g->NextGadget= CreateCheckbox(50,50,TRUE,0x0C);
if(g= g->NextGadget)
{ (void)AddGText(g,NULL,"CheckBox");
g->NextGadget= CreateStrGadget(100,80,80, 30,0x05);
if(g= g->NextGadget)
{ (void)AddGText(b2=g,"StrGadget","w/ text on both sides");
g->NextGadget= CreateButton(50,100,200,50,"Big Button",0xBB);
if(g= g->NextGadget)
{ (void)AddGText(g,"Left","Right");
g->NextGadget= CreateCycleButton(200,50,80,CycleTexts,0x00);
if(g= g->NextGadget)
{ g->NextGadget= CreateSlider(50,160,90, whichwitch, 100);
if(g= LastGadget(g))
{ g->NextGadget= CreateRadioButton(290,40,FALSE,42);
if(g= g->NextGadget)
{ (void)AddGText(g,NULL,"Radi_oButt_on");
g->NextGadget= CreateListView(330,100, 15, 7, ListViewTexts,1000);
if(g= LastGadget(g))
{ g->NextGadget= CreatePaletteButton(450,20, 26,11, 3, 123);
if(g= g->NextGadget)
{
; /* be happy */
}
else return 11;
}
else return 10;
}
else return 9;
}
else return 8;
}
else return 7;
}
else return 6;
}
else return 5;
}
else return 4;
}
else return 3;
}
else return 2;
}
if(nw= InitNewWindow(0L,"NewLook",600,220,NW_IDCMP,NW_FLAGS,glist))
{
/* open our window */
w= (struct Window *)OpenWindow(nw);
}
if(!w)
return 1;
{ struct Border *b= CreateFrame(0,0,400,50,10,5);
if(b)
DrawBorder(w->RPort,b,10,180);
/* else panic! */
}
SetScalebar(w, si= CreateScalebar(300,60, 200,13, -100,200), sN);
RefreshWindowFrame(w);
return 0;
}
int handleit()
{
int running= 1;
struct IntuiMessage *imsg;
ULONG class;
USHORT code;
struct Gadget *g;
Wait(1L << w->UserPort->mp_SigBit);
while(imsg=(struct IntuiMessage *)GetMsg(w->UserPort))
{ class = imsg->Class;
code = imsg->Code;
g = (struct Gadget *)imsg->IAddress;
ReplyMsg(imsg);
switch(class)
{
case CLOSEWINDOW:
printf("CLOSEWINDOW\n");
running= 0;
break;
case VANILLAKEY:
switch( (UBYTE)code )
{
case '\33': /* ESC */
running= 0;
break;
default:
printf("VANILLAKEY: %d\n",code);
break;
}
break;
case GADGETUP:
printf("GADGETUP: %d\n",g->GadgetID);
switch( g->GadgetID )
{
case 0x0B: /* Button */
if(g->Flags & SELECTED)
SetGFlags(w,b1, b1->Flags | SELECTED);
else
SetGFlags(w,b1, b1->Flags &~ SELECTED);
break;
case 0x0C: /* Checkbox */
if(g->Flags & SELECTED)
{ OnGadgetSafely(w,b0);
OnGadgetSafely(w,b2);
}
else
{ OffGadgetSafely(w,b0);
OffGadgetSafely(w,b2);
}
break;
case 0x05: /* StringGadget */
SetScalebar(w, si,sN=atol(((struct StringInfo *)(g->SpecialInfo))->Buffer));
break;
case 0xBB:
{ long n;
for(n=sN; n<250; SetScalebar(w, si,n++)) WaitTOF();
for(n=250; n>-150; SetScalebar(w, si,--n)) WaitTOF();
for(n=-150; n<sN; SetScalebar(w, si,n++)) WaitTOF();
}
break;
case 0x00:
DoCycleButton(w,g);
/* CycleButton's UserData is NewLook private! */
break;
}
break;
}
}
return running;
}
#ifdef DEBUG
extern void DebugSmartMemList(void);
#endif
main(int ac, char **av)
{
if(ac>1)
whichwitch= av[1];
if( openit() == 0 )
{
#ifdef DEBUG
printf("Memory allocated via SmartAllocate()\n");
DebugSmartMemList();
#endif
while( handleit() );
closeit();
#ifdef DEBUG
printf("\nSmartMem's Memory list at exit\n");
DebugSmartMemList();
#endif
}
exit(0);
}